﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MyRabbit.Application.Command.SlaughteCommand;
using MyRabbit.Application.ErrorCode;
using MyRabbit.Domain;

namespace MyRabbit.Web.Api.Controllers
{
    /// <summary>
    /// 屠宰控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class SlaughteController : ControllerBase
    {
        /// <summary>
        /// 中介者
        /// </summary>
        private readonly IMediator mediator;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator"></param>
        public SlaughteController(IMediator mediator)
        {
            this.mediator = mediator;
        }


        /// <summary>
        /// 添加屠宰信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<object>> AddSlaughte(SlaughteAddCommand command)
        {
            return await mediator.Send(command);
        }


        /// <summary>
        /// 修改屠宰信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>

        [HttpPost]
        public async Task<APIResult<object>> UpdateSlaughte(SlaughteUpdateCommand command)
        {
            return await mediator.Send(command);
        }

        /// <summary>
        /// 显示查询
        /// </summary>
        /// <param name="productId"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<Slaughte>> QuerySlaughte(int productId)
        {
            SlaughteQueryCommand command = new SlaughteQueryCommand();
            command.ProductId = productId;
            return await mediator.Send(command);
        }

    }
}
